// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.linqingying.gitcode.api.data

import com.intellij.collaboration.api.dto.GraphQLFragment
import com.intellij.openapi.util.NlsSafe
import com.linqingying.gitcode.api.GCRepositoryPath
import com.linqingying.gitcode.api.data.pullrequest.GCGitRefName

@GraphQLFragment("/graphql/fragment/repository.graphql")
class GCRepository(id: String,
                   val owner: GCRepositoryOwnerName,
                   val nameWithOwner: @NlsSafe String,
                   val viewerPermission: GCRepositoryPermissionLevel?,
                   val mergeCommitAllowed: Boolean,
                   val squashMergeAllowed: Boolean,
                   val rebaseMergeAllowed: Boolean,
                   val defaultBranchRef: GCGitRefName?,
                   val isFork: Boolean,
                   val url: @NlsSafe String,
                   val sshUrl: @NlsSafe String)
  : GCNode(id) {
  val path: GCRepositoryPath
  val defaultBranch = defaultBranchRef?.name

  init {
    val split = nameWithOwner.split('/')
    path = GCRepositoryPath(split[0], split[1])
  }
}
